import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            doctor: {
                id: '',
                name: '',
                phone: '',
                hospital: '',
                department: '',
                positional_title: '',
                qualification_pics: '',
                chest_card_pics: '',
            },
            qrcode: {
                head_image: '',
            },
            send: {
            },
        };
        return this.state;
    },
    getDoctor() {
        var me = this;
        var data = {id: me.state.doctor.id};
        var flag = true;
        if(me.beforeGetDoctor) {
            flag = me.beforeGetDoctor(data);
        }
        if(flag) {
            app.get("web/doctor/get", data, function(res) {
                me.setState({doctor: res.data.result});
                if(me.afterGetDoctor) {
                    me.afterGetDoctor(res);
                }
            });
        }
    },
    getQrcode() {
        var me = this;
        var data = {id: me.state.qrcode.id};
        var flag = true;
        if(me.beforeGetQrcode) {
            flag = me.beforeGetQrcode(data);
        }
        if(flag) {
            app.get("web/doctor/get", data, function(res) {
                me.setState({qrcode: res.data.result});
                if(me.afterGetQrcode) {
                    me.afterGetQrcode(res);
                }
            });
        }
    },
    getSend() {
        var me = this;
        var data = {id: me.state.send.id};
        var flag = true;
        if(me.beforeGetSend) {
            flag = me.beforeGetSend(data);
        }
        if(flag) {
            app.get("web/doctor/get", data, function(res) {
                me.setState({send: res.data.result});
                if(me.afterGetSend) {
                    me.afterGetSend(res);
                }
            });
        }
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {},
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
